import { Message } from 'amqplib';

export interface EventBus {
    Publish<TModel>(productId: string, topic: string, tag: string, id: string, message: TModel, options?: PublishOptions): Promise<boolean>;
    Subscribe<TModel>(productId: string, topic: string, callback: (model: TModel, message: Message) => boolean | Promise<boolean>, options?: SubscribeOptions): Promise<any>;
    Exit(): void;
    // Cast<T>(): T;
}

export interface AMQPAPI {
    SendToQueue(productId: string, queueName: string, message: Buffer, properties: any, options?: PublishOptions): Promise<boolean>;
}

/**
 * 消息消费模式
 * 
 * @export
 * @enum {number}
 */
export enum MessageConsumeModel {

    /**
     * 广播消费
     */
    Broadcasting = 1,

    /**
     * 集群消费,默认方式
     */
    Clustering = 2
}


/**
 * 消息订阅选项
 * 
 * @export
 * @class SubscribeOptions
 */
export interface SubscribeOptions {


    /**
     * 消息消费模式,默认集群模式
     * 
     * @type {MessageConsumeModel}
     * @memberof SubscribeOptions
     */
    Model?: MessageConsumeModel;

    /**
     * qos,默认:1
     * 
     * @type {number}
     * @memberof SubscribeOptions
     */
    BasicQOS?: number,

    /**
     * 是否共享channel,默认true
     * 
     * @type {boolean}
     * @memberof SubscribeOptions
     */
    ShardChannel?: boolean,

    /**
     * 消费失败的消息是否入列,默认true
     * 
     * @type {boolean}
     * @memberof SubscribeOptions
     */
    FalilMessageReQueue?: boolean
}

export interface PublishOptions {
    /**
     * 消息是否持久化存储
     * 
     * @type {boolean}
     * @memberof PublishOptions
     */
    DeliveryMode?: boolean,

    ShardChannel?: boolean
}

